/**
 * @author Manos Kapritsos
 */

import java.util.Enumeration;
import java.util.Hashtable;

public class Playlist {
    private Hashtable<String,String> list;

    public Playlist() {
        list = new Hashtable<String,String>();
    }

    public void add(String name, String url) {
        if(list.containsKey(name)) {
            System.err.println("Add failed. Key \""+name+"\" already exists");
        } else {
            list.put(name, url);
        }
    }

    public void delete(String name) {
        if(list.containsKey(name)) {
            list.remove(name);
        } else {
            System.err.println("Delete failed. Key \""+name+"\" does not exist.");
        }
    }

    public void edit(String name, String newUrl) {
        if(list.containsKey(name)) {
            list.put(name, newUrl);
        } else {
            System.err.println("Edit failed. Key \""+name+"\" does not exist.");
        }
    }

    public void printList() {
        if(list.isEmpty()) {
            System.out.println("The playlist is empty");
            return;
        }
        Enumeration keys = list.keys();
        String key;
        System.out.println("Printint playlist:");
        while(keys.hasMoreElements()) {
            key = (String)keys.nextElement();
            System.out.println(key+" "+list.get(key));
        }
        System.out.println();
    }

    public static void main(String[] args) {
        Playlist list = new Playlist();
        list.printList();
        list.add("Bohemian Rhapsody","http://www.youtube.com/watch?v=fJ9rUzIMcZQ");
        list.add("Bohemian Rhapsody (Classical Guitar)", "http://www.youtube.com/watch?v=pZ9jrBg4Lwc");
	list.add("Fur Elise", "http://www.youtube.com/watch?v=_mVW8tgGY_w");
        list.printList();
        list.delete("Bohemian Rhapsody");
        list.printList();
        list.delete("nonexistentkey");
        list.printList();
        list.edit("Fur Elise","http://www.youtube.com/watch?v=TWP6UoyQ--s");
        list.printList();
    }
}
